package com.itheima.app.mapper;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.domain.mongo.Video;
import com.itheima.service.mongo.VideoService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MQVideoManager {
    //针对动态的操作
    public static final Integer VIDEO_PUBLISH = 1;// 发视频
    public static final Integer VIDEO_LIKE = 2;// 点赞
    public static final Integer VIDEO_DISLIKE = 3;// 取消点赞
    public static final Integer VIDEO_COMMENT = 4;// 评论视频

    @Reference
    private VideoService videoService;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void sendVideoMsg(String videoId, Integer type) {
        // 根据movementId查询动态
        Video video = videoService.findVideoById(videoId);

        // 构建消息内容
        Map<String, Object> message = new HashMap<>();
        message.put("vid", video.getVid().toString());
        message.put("userId", UserHolder.getUser().getId());
        message.put("type", type.toString());
        rocketMQTemplate.convertAndSend("video-recommend", message);
    }
}
